package rule;

import entity.Student;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  测试
 * </P>
 *
 * @author dingwen
 * @date 2021.09.09 12:01
 */
public class Test {
    public static void main(String[] args) {

        // 多值多判断情况
        RuleDto<Map<String, String>> usernameRuleDto = new RuleDto<>();

        HashMap<String, String> valueMap = new HashMap<>(2);
        valueMap.put(UserNameRule.class.getSimpleName(), "dingwen");
        valueMap.put(PasswordRule.class.getSimpleName(), "123456");
        usernameRuleDto.setValue(valueMap);

        RuleService<Boolean, Map<String, String>> ruleService = RuleService.getInstance();
//        Boolean r1 = ruleService.and()
//                .builder(new UserNameRule("dingwen"))
//                .builder(new PasswordRule())
//                .build()
//                .execute(usernameRuleDto);
//
//        System.out.println("r1 = " + r1);
//
//        Boolean r2 = ruleService.or()
//                .builder(new UserNameRule("dingwen"))
//                .builder(new PasswordRule())
//                .build()
//                .and()
//                .builder(new UserNameRule("dingwen"))
//                .builder(new PasswordRule())
//                .build()
//                .execute(usernameRuleDto);
//        System.out.println("r2 = " + r2);

//        Boolean r3 = ruleService.or()
//                .builder(new UserNameRule("din1gwen"))
//                .builder(new PasswordRule())
//                .build()
//                .or()
//                .builder(new UserNameRule("dingwen"))
//                .builder(new PasswordRule())
//                .build()
//                .execute(usernameRuleDto);
//        System.out.println("r3 = " + r3);

//        Boolean r4 = ruleService.and()
//                .builder(new UserNameRule("dingwen"))
//                .builder(new PasswordRule())
//                .build()
//                .and()
//                .builder(new UserNameRule("dingwen"))
//                .builder(new PasswordRule())
//                .build()
//                .execute(usernameRuleDto);
//        System.out.println("r4 = " + r4);


                Boolean r6 = ruleService.and()
                .builder(new UserNameRule("dingwen"))
                .builder(new PasswordRule())
                .build()
                .or()
                .builder(new UserNameRule("dingwen"))
                .builder(new PasswordRule())
                .build()
                .execute(usernameRuleDto);
        System.out.println("r6 = " + r6);


//        // 指定规则指定返回类型
//        RuleDto<Student> studentRuleDto = new RuleDto<>();
//        Student student = new Student();
//        student.setName("dingwen");
//        studentRuleDto.setValue(student);
//        Double sore = RuleService.<Double, Student>getInstance().execute(studentRuleDto, new StudentRule());
//        System.out.println("sore = " + sore);
//
//        // 指定规则没有返回值
//
//        RuleDto<String> stringRuleDto = new RuleDto<>();
//        stringRuleDto.setValue("y");
//
//        RuleService.<Object,String>getInstance().executeVoid(stringRuleDto,new PrintRule());
//
//
//        // 一个条件对应不同返回值
//        RuleDto<String> ruleDto = new RuleDto<>();
//        ruleDto.setValue("张三");
//        RuleService<Student, String> ruleService1 = RuleService.getInstance();
//        Student student1 = ruleService1.execute(ruleDto, new Student2Rule());
//        System.out.println("student1 = " + student1);


    }
}
